package com.wander.concurrent;

public class ThreadSafetyExample {
    private static int count = 0;
    public static void increment() {
        count++;
    }

    public static int get() {
        return count;
    }

    public static void main(String[] args) {
        int threadCount = 100;
        System.out.println("如果打印的最大值小于" + threadCount + "出现了共享变量线程安全问题");
        for (int i = 0; i < threadCount; i++) {
            new Thread(()->{
                //模拟一个随机延时
                for (int j = 0; j < Integer.MAX_VALUE; j++) ;
                increment();
                System.out.println(get());
            }).start();
        }
    }
}
